package com.demo.commons.results;

import com.demo.commons.utils.StringUtils;

public abstract class Results {

	/**
	 * 返回成功，不带业务参数
	 * 
	 * @return
	 */
	public static CommonResult<?> success() {
		return CommonResult.builder().code(CommonEnum.SUCCESS.getCode()).msg(CommonEnum.SUCCESS.getMsg()).build();
	}
	
//	/**
//	 * 返回成功，不带业务参数
//	 * 
//	 * @return
//	 */
//	public static CommonResult<?> success(String msg) {
//		return CommonResult.builder().code(CommonEnum.SUCCESS.getCode()).msg(msg).build();
//	}

	/**
	 * 返回成功，携带业务参数
	 * 
	 * @param data
	 * @return
	 */
	public static <T> CommonResult<T> success(T data) {
		return CommonResult.<T>builder().code(CommonEnum.SUCCESS.getCode()).msg(CommonEnum.SUCCESS.getMsg()).data(data)
				.build();
	}

	/**
	 * 返回失败
	 * 
	 * @param msg
	 * @param apped 追加错误原因
	 * @return
	 */
	public static CommonResult<?> error(String msg, Object... apped) {
		return CommonResult.builder().code(CommonEnum.TY_ERROR.getCode()).msg(StringUtils.format(msg, apped)).build();
	}

	/**
	 * 返回失败,需要对msg添加错误原因
	 * 
	 * @param code
	 * @param msg
	 * @param apped 追加错误原因
	 * @return
	 */
	public static CommonResult<?> error(Integer code, String msg, Object... apped) {
		return CommonResult.builder().code(code).msg(StringUtils.format(msg, apped)).build();
	}

	/**
	 * 系统错误
	 * 
	 * @return
	 */
	public static CommonResult<?> serverError() {
		return CommonResult.builder().code(CommonEnum.SERVER_ERROR.getCode()).msg(CommonEnum.SERVER_ERROR.getMsg())
				.build();
	}

	/**
	 * 未知错误
	 * 
	 * @return
	 */
	public static CommonResult<?> unknownError() {
		return CommonResult.builder().code(CommonEnum.UNKNOWN_ERROR.getCode()).msg(CommonEnum.UNKNOWN_ERROR.getMsg())
				.build();
	}
	
	/**
	 * 未知错误
	 * 
	 * @return
	 */
	public static CommonResult<?> unknownError(String msg) {
		return CommonResult.builder().code(CommonEnum.UNKNOWN_ERROR.getCode()).msg(msg)
				.build();
	}

	/**
	 * 调用此方法传入eumn的枚举值即可，如：CommonResult.build(CommonEumn.SUCCESS)
	 * 
	 * @param error
	 * @return
	 */
	public static CommonResult<?> build(CommonEnum error) {
		return CommonResult.builder().code(error.getCode()).msg(error.getMsg()).build();
	}

	/**
	 * 自定义返回码、返回描述
	 * 
	 * @param code
	 * @param msg
	 * @param data
	 * @return
	 */
	public static <T> CommonResult<T> build(Integer code, String msg, T data) {
		return CommonResult.<T>builder().code(code).msg(msg).data(data).build();
	}

	/**
	 * 自定义返回码、返回描述
	 * 
	 * @param code
	 * @param msg
	 * @return
	 */
	public static CommonResult<?> build(Integer code, String msg) {
		return CommonResult.builder().code(code).msg(msg).build();
	}

	

}
